package com.qf.controller;

import com.qf.pojo.Car;
import com.qf.pojo.ResponseData;
import com.qf.service.CarService;
import com.qf.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import static java.awt.SystemColor.info;

@Controller
@RequestMapping("/car")
public class CarSys {
    @Autowired
    private CarService carService;
    @ResponseBody
@RequestMapping("/price")
    public ResponseData price (@RequestParam("getid") Integer cid){
        //调用业务层,查询数据
//        System.out.println(cid);
//        System.out.println(carService);
        List<Car> list = carService.findAll(cid);
//        System.out.println(info);
        if (info==null){
            return JsonUtils.createJson(0,"商品不存在");
        }
        return JsonUtils.createJson(1,list);
    }
    @RequestMapping("/number")
    @ResponseBody
    public ResponseData number(@RequestParam("getid") Integer cid){
        //调用业务层
        List<Car> list = carService.findAllByNumber(cid);
        if (info==null){
            return JsonUtils.createJson(0,"商品不存在");
        }
        return JsonUtils.createJson(1,list);
    }
    @ResponseBody
    @RequestMapping("/findcar")
    public ResponseData findCar(@RequestParam("getid") Integer id){
        Car car = carService.findCarById(id);
        //判断
        if (car==null){
            return JsonUtils.createJson(0,"查询不到");
        }
        return JsonUtils.createJson(1,car);
    }
}
